<script setup lang="ts">
import { ref } from "vue";
import DeviceCategoryApi from "@/api/DeviceCategoryApi";
import { useLocalStore } from "@/views/report/dotline/components/store";
interface Tree {
  label: string;
  children?: Tree[];
  id: number | string;
}

const localStore = useLocalStore();
const isShow = ref(true);
const pointData = ref([]);
const lineData = ref([]);
const activePointId = ref(null);
const activeLineId = ref(null);

const getAllData = () => {
  const params1 = {
    pageSize: 100,
    pageIndex: 1,
    pClassId: "01",
  };
  const params2 = {
    pageSize: 100,
    pageIndex: 1,
    pClassId: "02",
  };
  DeviceCategoryApi.api_query_point(params1).then(({ data, succeeded }) => {
    if (succeeded) {
      pointData.value = data;
    }
  });
  DeviceCategoryApi.api_query_line(params2).then(({ data, succeeded }) => {
    if (succeeded) {
      lineData.value = data;
    }
  });
};
onMounted(() => getAllData());
</script>

<template>
  <div class="thematic-map" v-if="isShow">
    <div class="title">专题展示</div>
    <div class="pipe-category">管点专题</div>
    <div class="point-list">
      <div
        v-for="point in pointData"
        :key="point.classId"
        :class="{ active: point.classId === activePointId }"
        @click="
          activePointId = point.classId;
          localStore.setVisiblePointClassIds([point.classId]);
        "
      >
        <span>{{ point.className }}</span>
        <span>{{ point.num }}个</span>
      </div>
    </div>
    <div class="pipe-category">管段专题</div>
    <div class="line-list">
      <div
        v-for="line in lineData"
        :key="line.classId"
        :class="{ active: line.classId === activeLineId }"
        @click="
          activeLineId = line.classId;
          localStore.setVisibleLineClassIds([line.classId]);
        "
      >
        <span>{{ line.className }}</span>
        <span>{{ (line.length / 1000).toFixed(2) }}千米</span>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.thematic-map {
  position: absolute;
  top: 10px;
  left: 15px;
  z-index: 1000;
  width: 340px;
  height: 800px;
  font-family: Roboto, sans-serif;
  font-size: 14px;
  line-height: 20px;
  color: rgb(16 16 16 / 100%);
  background-color: rgb(255 255 255 / 100%);
  border: 1px solid rgb(25 144 255 / 100%);
  border-radius: 3px;
}

.title {
  height: 70px;
  font-size: 28px;
  font-weight: bold;
  line-height: 70px;
  text-align: center;
}

.pipe-category {
  height: 45px;
  padding-left: 20px;
  font-size: 16px;
  line-height: 45px;
  color: rgb(255 255 255 / 100%);
  background-color: rgb(25 144 255 / 100%);
  border: 1px solid rgb(255 255 255 / 100%);
  border-radius: 3px;
}

.point-list,
.line-list {
  height: 300px;
  overflow-y: auto;

  div {
    display: flex;
    justify-content: space-between;
    height: 40px;
    padding: 0 10px;
    line-height: 40px;
    cursor: pointer;
    border-bottom: 1px solid rgb(128 128 128 / 10%);

    span {
      margin: 0 5px;
    }
  }

  .active {
    background: #878a99;
  }
}
</style>
